<?php


namespace app\controllers;

use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\Response;

class IndexController extends Controller
{
    public function actionIndex()
    {
        phpinfo();
    }

    /**
     * 打印模块ID
     */
    public function actionModules()
    {
        \Yii::$app->response->format = Response::FORMAT_JSON;
        $modules = \Yii::$app->getModules();
        $data = [];
        foreach ($modules as $module) {
            $data['modules'][] = $module->id;
        }
        foreach (\Yii::$app->loadedModules as $module) {
            $data['loadedModules'][] = $module->id;
        }
        return $data;
    }

    /**
     * 自定义递归函数，递归数组
     */
    public function actionRecursion()
    {
        $data = ['name' => 'lisi', 'age' => 20, 'ctime' => time(),'attr' => [['name' => 'phone', 'years' => 1, 'utime' => time()]]];
        \app\kit\Common::array_recursion($data, function ($item) {
            return is_int($item) || is_float($item) ? strval($item) : $item;
        });
        //\app\kit\Common::array_recursion_fields($data, ['ctime', 'utime'], function ($val) { return date('Y-m-d H:i:s', $val); });
        $this->asjson($data);
    }

    public function actionTime()
    {
        $date = date('Y-m-i H:i:s',time());
        $rt['timezone'] = $timezone =  date_default_timezone_get();
        $rt['date'] = $date;
        $rt['date_c'] = date('c', strtotime($date));
        $rt['date_p'] = date('Y-m-i H:i:s P', strtotime($date));
        $rt['utc_date'] = \app\kit\Common::time_convert($date, 'UTC', $timezone);
        $rt['utc_date_c'] = date('c', strtotime($rt['utc_date']));
        $rt['utc_date_P'] = date('Y-m-i H:i:s P', strtotime($rt['utc_date']));
        $this->asjson($rt);
    }
}